#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

int main()
{
Mat img=imread("/home/lwj/opencv.21/mm.jpg");
if(img.empty ())
{
    cout<<"no"<<endl;
    return -1;
}
Mat gray,qrcode_bin;
cvtColor(img,gray,COLOR_BGR2GRAY);
QRCodeDetector qrcodedetector;
vector<Point>points;
string information;
bool isQRcode;
isQRcode=qrcodedetector.detect(gray,points);//识别🏇
if(isQRcode)
{
    //解码
    information=qrcodedetector.decode(gray,points,qrcode_bin);
    cout<<points<<endl;
}
else
{
cout<<"无法识别二维码"<<endl;
return -1;
}
//绘制二维码边框
for(int i=0;i<points.size();i++)
{
    if(i==points.size()-1)
    {
        line(img,points[i],points[0],Scalar(0,0,255),2,8);
        break;
    }
    line(img,points[i],points[i+1],Scalar(0,0,255),2,8);
}
 //解码内容
putText(img,information.c_str(),Point(20,30),0,1.0,Scalar(0,0,255),2,8);

 //识别🏇解码
//  string information2;
//  vector<Point>points2;
//  information2=qrcodedetector.detectAndDecode(gray,points);
//  cout<<points<<endl;
//  putText(img,information2.c_str(),Point(20,30),0,1.0,Scalar(0,0,255),2,8);

imshow("result",img);//解码结果
namedWindow("qrcode_bin",WINDOW_NORMAL);
imshow("qrcode_bin",qrcode_bin);//校正和二值化后的🏇

waitKey(0);
    return 0;
}